from django.contrib import admin
from .models import UserProfile

from django.contrib.auth.admin import UserAdmin
from django.utils.translation import gettext_lazy


class UserProfileAdmin(UserAdmin):
    def post_historyqa_permission(self, obj):
        # return obj.authority.name
        return [pt.name for pt in obj.historyqa_permission.all()]
    def post_knowledge_permission(self, obj):
        # return obj.authority.name
        return [pt.name for pt in obj.knowledge_permission.all()]
    post_historyqa_permission.short_description = "历史对话管理权限"
    post_knowledge_permission.short_description = "知识库权限"
    list_display = ('username', 'post_historyqa_permission', 'post_knowledge_permission', 'is_staff', 'is_superuser')
    list_filter = ['is_superuser']
    search_fields = ['is_superuser']
    list_per_page = 10
    
    # fieldsets = (
    #     (None, {'fields': ('username', 'password', 'first_name', 'last_name', 'email')}),
    #     (gettext_lazy('权限管理'), {'fields': ('historyqa_permission', 'knowledge_permission')}), # 添加模型里的字段openid
    #     (gettext_lazy('Permissions'), {'fields': ('is_superuser', 'is_staff', 'is_active')}),
    # )
    
    

admin.site.register(UserProfile, UserProfileAdmin)